/*
 * ATKPropertyRendererFactory.java
 *
 * Created on 22 juni 2007, 9:09
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package net.jwtools.tmt.ui.propertyeditor;

import java.awt.Color;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

import net.jwtools.tmt.ui.renderer.ComboBoxTableCellRenderer;

import com.l2fprod.common.propertysheet.Property;
import com.l2fprod.common.propertysheet.PropertyRendererFactory;
import com.l2fprod.common.swing.renderer.BooleanCellRenderer;
import com.l2fprod.common.swing.renderer.ColorCellRenderer;

/**
 * 
 * @author mesui00
 */
public class BasePropertyRendererFactory implements PropertyRendererFactory {

	/** Creates a new instance of ATKPropertyRendererFactory */
	public BasePropertyRendererFactory() {
	}

	public TableCellRenderer createTableCellRenderer(Property p) {
		ExtendedProperty property = (ExtendedProperty) p;
		TableCellRenderer renderer = null;
		if (isList(property.getDisplayType())) {
			renderer = new ComboBoxTableCellRenderer();
			((ComboBoxTableCellRenderer) renderer).setAvailableValues(property
					.getAllowedvalues());
		} else if (property.getDisplayType().equals(Boolean.class)) {
			renderer = new BooleanCellRenderer();
		} else if (property.getDisplayType().equals(Color.class)) {
			renderer = new ColorCellRenderer();
		} else if (property.getDisplayType().equals(Date.class)) {
			renderer = new DateTableCellRenderer();
			System.out.println(p.getName());
		} else if (property.getDisplayType().equals(Long.class)) {
			renderer = new DefaultTableCellRenderer();
		} else if (property.getDisplayType().equals(String.class)) {
			renderer = new DefaultTableCellRenderer();
		}

		return renderer;
	}

	public TableCellRenderer createTableCellRenderer(Class aClass) {
		System.out.println("trying for " + aClass);
		return null;
	}

	private boolean isList(Class aClass) {
		Class[] ifaces = aClass.getInterfaces();
		if (ifaces == null)
			return false;
		for (int idx = 0; idx < ifaces.length; idx++)
			if (ifaces[idx].equals(List.class))
				return true;
		return false;
	}

	public static void main(String[] a) {
		new BasePropertyRendererFactory()
				.createTableCellRenderer(LinkedList.class);
	}
}
